var resList = ['./img/bg.jpg',
    './img/h_R0.png',
    './img/h_R1.png',
    './img/h_R2.png',
    './img/h_R3.png',
    './img/h_R4.png',
    './img/h_R5.png',
    './img/h_R6.png',
    './img/h_R7.png',
    './img/h_L0.png',
    './img/h_L1.png',
    './img/h_L2.png',
    './img/h_L3.png',
    './img/h_L4.png',
    './img/h_L5.png',
    './img/h_L6.png',
    './img/h_L7.png',
    './img/attack/a1-L0.png',
    './img/attack/a1-L1.png',
    './img/attack/a1-L2.png',
    './img/attack/a1-L3.png',
    './img/attack/a1-L4.png',
    './img/attack/a1-L5.png',
    './img/attack/a1-R0.png',
    './img/attack/a1-R1.png',
    './img/attack/a1-R2.png',
    './img/attack/a1-R3.png',
    './img/attack/a1-R4.png',
    './img/attack/a1-R5.png',
    './img/enemy/1.png',
    './img/enemy/2.png',
    './img/enemy/3.png',
    './img/enemy/4.png',
    './img/enemy/5.png',
    './img/enemy/6.png',
    './img/enemy/7.png',
    './img/enemy/8.png',
    './img/enemy/9.png',
    './img/enemy/10.png',
    './img/enemy/11.png',
    './img/enemy/12.png',
    './img/enemy/13.png',
    './img/enemy/14.png',
    './img/enemy/15.png',
    './img/enemy/16.png',
    './img/head0.jpg',
    './img/boom/frame_0.png',
    './img/boom/frame_1.png',
    './img/boom/frame_2.png',
    './img/boom/frame_3.png',
    './img/boom/frame_4.png',
    './img/boom/frame_5.png',
    './img/boom/frame_6.png',
    './img/boom/frame_7.png',
    './img/boom/frame_8.png',
    './img/boom/frame_9.png',
    './img/boom/frame_10.png',
    './img/boom/frame_11.png',
    './img/boom/frame_12.png',
    './img/boom/frame_13.png',
    './img/boom/frame_14.png',
    './img/boom/frame_15.png',
    './img/boom/frame_16.png',
    './img/boom/frame_17.png',
    './img/boom/frame_18.png',
    './img/boom/frame_19.png',
    './img/boom/frame_20.png',
    './img/boom/frame_21.png',
    './img/boom/frame_22.png',
    './img/boom/frame_23.png',
    './img/boom/frame_24.png',
    './img/boom/frame_25.png',
];
var resObj = [];
var loadCount = 0;
for (var i = 0; i < resList.length; i++) {
    var img = new Image();
    img.src = resList[i];
    resObj.push(img);
    img.onload = function () {
        loadCount++;
        if (loadCount == resList.length) {
            console.log("资源加载完成");
            //资源加载完成以后就应该开始游戏
            // startGame();
            bg = new Background();
            bg.draw(ctx);

            var btn = document.querySelector('button');
            var box = document.getElementById('box')
            var bigBox = document.getElementById('big-box')
            btn.onclick = function () {
                box.style.display = 'block';

                bigBox.style.animationPlayState = 'running';

                var audio = document.createElement('audio');
                audio.loop = true;
                audio.src = './music/bg1.mp3';
                audio.play();
                btn.remove();

                bigBox.onanimationend = function () {
                    box.remove();
                    startGame();
                }
            }
        }
    }
}